package com.situ.tos2024.model;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonValue;
import com.situ.tos2024.util.AbstractEnum;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 外卖订单表
 * t_business_order
 */
@Getter
@Setter
@ToString
@JsonIgnoreProperties("handler")
public class Order extends AbstractEntity {
    /**
     * 订单编号
     */
    private String orderNo;

    /**
     * 店铺编号
     */
    private Integer storeId;

    /**
     * 用户编号
     */
    private Integer userId;

    /**
     * 下单时间
     */
    private LocalDateTime orderTime;

    /**
     * 收货人姓名
     */
    private String receiverName;

    /**
     * 收货人地址
     */
    private Address receiverAddress;

    /**
     * 收货人地址详情
     */
    private String receiverAddrDetail;

    /**
     * 收货人电话
     */
    private String receiverPhone;

    /**
     * 订单总价
     */
    private BigDecimal totalPrice;

    /**
     * 实收价
     */
    private BigDecimal actualPrice;

    /**
     * 支付方式
     */
    private String payType;

    /**
     * 派送方式
     */
    private String shippingMethod;

    /**
     * 订单状态
     */
    private OrderStatus orderStatus;

    /**
     * 备注
     */
    private String description;

    /**
     * 订单明细
     */
    private List<OrderDetail> details;

    /**
     * 订单状态
     */
    public enum OrderStatus implements AbstractEnum {
        CREATED(0, "已创建"),
        TO_BE_PAID(1, "待支付"),
        PAID(2, "已支付"),
        PROCESSING(3, "备货中"),
        SHIPPED(4, "已发货"),
        CONFIRMED(5, "已收货"),
        TO_BE_EVALUATED(6, "待评价"),
        EVALUATED(7, "已评价"),
        CLOSED(8, "已关闭"),
        REFUND_REQUESTING(9, "申请退款中"),
        REFUND_APPROVED(10, "退款申请通过"),
        REFUND_REJECTED(11, "退款申请驳回"),
        REFUND_PROCESSING(12, "退款中"),
        REFUNDED(13, "已退款"),
        CANCELED(14, "已取消"),
        DISABLED(15, "已作废");

        private final int code;
        private final String name;

        OrderStatus(int code, String name) {
            this.code = code;
            this.name = name;
        }

        //使用此注解可以让jackson在序列化时，序列化为此属性的值或此方法的返回值，而不是枚举的名称
        //此注解可以标注在属性上，也可以标注在方法上
        @JsonValue
        @Override
        public String getName() {
            return this.name;
        }

        public int getCode() {
            return this.code;
        }

        @Override
        public String toString() {
            return this.getName();
        }
    }
}